




#define UserInfoHeight 400


#import "HAccontView.h"
#import "HUserInfo.h"
#import "HUserSet.h"
#import "UserAccount.h"

#import "HUserInfoView.h"

@interface HAccontView ()
///用户信息界面
@property (nonatomic ,strong) HUserInfo *userInfo;
///用户设置界面
@property (nonatomic ,strong) HUserSet *userSet;

///用户信息界面
@property (nonatomic ,strong) HUserInfoView *userInfoView;
@end

@implementation HAccontView

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"%s",__func__);
//    [self setUI];
    
    if ([UserAccount sharedUserAccount].islogin) {
        
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%s",__func__);
    //背景色
    self.view.backgroundColor = [UIColor whiteColor];
    //设置导航栏字体
    self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:17],NSForegroundColorAttributeName:[UIColor whiteColor]};

    [self setUI];
    
    UIBarButtonItem *testB = [[UIBarButtonItem alloc]initWithTitle:@"ceshi" style:UIBarButtonItemStylePlain target:self action:@selector(text)];
    self.navigationItem.rightBarButtonItem = testB;
}
- (void) text {
    NSLog(@"%s",__func__);
    NSLog(@"%f",_userInfoView.distanceLeft);
//    _userInfoView.distanceLeft = 100;
    [UIView animateWithDuration:2 animations:^{
        [self.view layoutIfNeeded];
    }];
}


///加载控件
- (void) setUI{

    
//    [self loadUserInfo];
    [self loadUserInfoView];
    [self loadUserSet];
}



///加载用户信息
- (void)loadUserInfoView{
    
    _userInfoView = [[HUserInfoView alloc]init];
    _userInfoView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_userInfoView];
    

    _userInfoView.translatesAutoresizingMaskIntoConstraints = false;
    //左
    NSLayoutConstraint *leftC = [NSLayoutConstraint constraintWithItem:_userInfoView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:0];
    //右
    NSLayoutConstraint *rightC = [NSLayoutConstraint constraintWithItem:_userInfoView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0];
    //上
    NSLayoutConstraint *topC = [NSLayoutConstraint constraintWithItem:_userInfoView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0];
    //高
    NSLayoutConstraint *heightC = [NSLayoutConstraint constraintWithItem:_userInfoView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:[_userInfoView heightWithIsEnter:NO]];

    [self.view addConstraints:@[leftC,rightC,topC,heightC]];

}

///加载用户信息
- (void)loadUserInfo{
    
    _userInfo = [[HUserInfo alloc]init];
    [self.view addSubview:_userInfo.view];
#pragma 非常重要-———-添加控制器
    [self addChildViewController:_userInfo];
    
    _userInfo.view.translatesAutoresizingMaskIntoConstraints = false;
    //左
    NSLayoutConstraint *leftC = [NSLayoutConstraint constraintWithItem:_userInfo.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:0];
    //右
    NSLayoutConstraint *rightC = [NSLayoutConstraint constraintWithItem:_userInfo.view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0];
    //上
    NSLayoutConstraint *topC = [NSLayoutConstraint constraintWithItem:_userInfo.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0];
    //高
    NSLayoutConstraint *heightC = [NSLayoutConstraint constraintWithItem:_userInfo.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:[_userInfo heightWithIsEnter:YES]];
    [self.view addConstraints:@[leftC,rightC,topC,heightC]];
    
}

///加载用户设置
- (void)loadUserSet{
    _userSet = [[HUserSet alloc]initWithStyle:UITableViewStyleGrouped];
    [self.view addSubview:_userSet.view];
#pragma 非常重要-———-添加控制器
    [self addChildViewController:_userSet];
    
    _userSet.view.translatesAutoresizingMaskIntoConstraints = false;
    //左
    NSLayoutConstraint *leftC = [NSLayoutConstraint constraintWithItem:_userSet.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:0];
    //右
    NSLayoutConstraint *rightC = [NSLayoutConstraint constraintWithItem:_userSet.view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0];
    //上
    NSLayoutConstraint *topC = [NSLayoutConstraint constraintWithItem:_userSet.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_userInfoView attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
    //下
    NSLayoutConstraint *heightC = [NSLayoutConstraint constraintWithItem:_userSet.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
    
    [self.view addConstraints:@[leftC,rightC,topC,heightC]];
    
    //传递数据
    _userSet.userData = self.userSetData;
    
}
///懒加载
/*
- (HUserInfo *)userInfo
{
    if (!_userInfo) {
        _userInfo = [[HUserInfo alloc]init];
    }
    return _userInfo;
}

- (HUserSet *)userSet
{
    if (!_userSet) {
        _userSet = [[HUserSet alloc]initWithStyle:UITableViewStyleGrouped];
    }
    return _userSet;
}
*/

- (NSArray *)userSetData
{
    if (!_userSetData) {
        _userSetData = [[NSArray alloc]init];
    }
    return _userSetData;
}

- (void)dealloc{
    NSLog(@"1");
}


@end
